package test;

import java.math.BigInteger;

public class QQParser {
	private static final String QQ_VIDEO_URL = "http://vtop.qqvideo.tc.qq.com/";

	public static void main(String[] args) {
		String vid = "7tBGpHA4vbP";
		
		System.out.println(getVideoURL(vid));
	}

	private static String getVideoURL(String vid){
		BigInteger modder = BigInteger.valueOf(10000 * 10000);
		BigInteger fs = getTot(vid).remainder(modder);
		String videoURL = QQ_VIDEO_URL + fs.toString() + "/" + vid + ".flv";
		return videoURL;
	}

	private static BigInteger getTot(String vid){
		BigInteger modder = new BigInteger("4294967296");
		BigInteger tot = BigInteger.valueOf(0);

		for(int i=0; i<vid.length(); i++){
			int c = vid.charAt(i);
			tot = tot.multiply(BigInteger.valueOf(33)).add(BigInteger.valueOf(c));

			if(tot.compareTo(modder) >= 0){
				tot = tot.remainder(modder);
			}
		}
		return tot;
	}
}
